/**
 * Created by huotaol on 2017/5/25.
 */
import React, {Component} from "react";
import {View} from "react-native";
import {connect} from "react-redux";
import Util from "../../main/Util";
import CarList from "../buyCar/component/CarList";
import ModuleCommonHeader from "../../main/module/ModuleCommonHeader";
import * as StorageConstant from "../../constant/Storage";
import * as MineAction from "../../redux/action/Mine";


class ViewCollect extends Component {
    // 构造
    constructor(props) {
        super(props);
        // 初始状态
        this.state = {};
        this._loadData = this._loadData.bind(this);
    }

    render() {
        return (
            <View style={{flex: 1}}>
                <ModuleCommonHeader title={'浏览记录'}/>
                <CarList
                    pagination={false}
                    refreshable={false}
                    onFetch={this._loadData}/>
            </View>
        );
    }

    _loadData(page = 1, options) {
        return Util.storage.getAllDataForKey(StorageConstant.STORAGE_VIEW_CAR)
            .then(ret => {
                console.log('ViewCollect  ' + ret.length);
                this.props.updateView(ret.length);
                return {data: ret, finish: true};
            });
    }
}

const mapStateToProps = (state) => {
    return {};
};

const mapDispatchToProps = (dispatch) => {
    return {
        updateView: count => dispatch(MineAction.view(count)),
    };
};

export default connect(mapStateToProps, mapDispatchToProps)(ViewCollect);

